package day04;

import java.util.ArrayList;
import java.util.LinkedList;

/**
 * @Auther: sky
 * @Date: 2019/2/27 22:49
 * @Description:
 */
public class Capability2List {


    public static void main(String[] args){

        long n = (long)1E6;

        ArrayList arrayList = new ArrayList();
        long milis = System.currentTimeMillis();
        for(int i= 0; i<n; i++){
            arrayList.add(i);
        }
        System.out.println("新增操作arraylist 花费了  "+(System.currentTimeMillis()-milis) +" 毫秒");

        LinkedList linkedList = new LinkedList();
        milis = System.currentTimeMillis();
        for(int i= 0; i<n; i++){
            linkedList.add(i);
        }
        System.out.println("新增操作linkedlist 花费了  "+(System.currentTimeMillis()-milis) +" 毫秒");

        // arraylist删除元素
        milis = System.currentTimeMillis();
        arrayList.remove(1E5);
        System.out.println("删除元素arraylist 花费了  "+(System.currentTimeMillis()-milis) +" 毫秒");

        // linkedlist删除元素
        milis = System.currentTimeMillis();
        linkedList.remove(1E5);
        System.out.println("删除元素linkedlist 花费了  "+(System.currentTimeMillis()-milis) +" 毫秒");

        // arraylist get 中间元素
        milis = System.currentTimeMillis();
        arrayList.get((int)n/2);
        System.out.println("访问中间元素arraylist 花费了  "+(System.currentTimeMillis()-milis) +" 毫秒");

        // linkedlist get 中间元素
        milis = System.currentTimeMillis();
        linkedList.get((int)n/2);
        System.out.println("访问中间元素linkedlist 花费了  "+(System.currentTimeMillis()-milis) +" 毫秒");


    }



}
